package com.ht.medicaltreatment.adapter

import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.ht.medicaltreatment.R
import com.ht.medicaltreatment.bean.SubjectListDataPage

class SubjectListAdapter : BaseQuickAdapter<SubjectListDataPage,BaseViewHolder>(
    R.layout.item_subject_list_layout){

    override fun convert(holder: BaseViewHolder, item: SubjectListDataPage) {
        holder.setText(R.id.tvCode,"${getItemPosition(item)+1}")
        holder.setText(R.id.tvName,item.protocolNumber)
        holder.setText(R.id.titleProgress,"已使用："+item.consumableUseProgress)
        val split = item.consumableUseProgress?.split("/")
        var progress = 0
        if(split[1].toInt() > 0){
            progress = (split[0].toFloat()/split[1].toFloat()*100).toInt()
        }
        holder.setText(R.id.tvProgress,"$progress %")
        val progressRecyclerview = holder.getView<RecyclerView>(R.id.progressRecyclerview)
        progressRecyclerview.layoutManager = LinearLayoutManager(context).apply { orientation = LinearLayoutManager.HORIZONTAL }
        val adapter = SubjectProgressAdapter()
        progressRecyclerview.adapter = adapter

        val progressList = mutableListOf(false,false,false,false,false,false,false,false,false,false)
        val p = progress / 10
        for (i in 1..p){
            progressList[i-1] = true
        }
        adapter.setNewInstance(progressList)
    }
}
